﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FeiQubuke.Models;

namespace FeiQubuke.Controllers
{
    public class CanYaoController : Controller
    {
        private eatEntities db = new eatEntities();

        //
        // GET: /CanYao/

        public ActionResult Index()
        {
            return View(db.canyaos.ToList());
        }

        //
        // GET: /CanYao/Details/5

        public ActionResult Details(int id = 0)
        {
            canyao canyao = db.canyaos.Find(id);
            if (canyao == null)
            {
                return HttpNotFound();
            }
            return View(canyao);
        }

        //
        // GET: /CanYao/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /CanYao/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(canyao canyao)
        {
            if (ModelState.IsValid)
            {
                db.canyaos.Add(canyao);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(canyao);
        }

        //
        // GET: /CanYao/Edit/5

        public ActionResult Edit(int id = 0)
        {
            canyao canyao = db.canyaos.Find(id);
            if (canyao == null)
            {
                return HttpNotFound();
            }
            return View(canyao);
        }

        //
        // POST: /CanYao/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(canyao canyao)
        {
            if (ModelState.IsValid)
            {
                db.Entry(canyao).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(canyao);
        }

        //
        // GET: /CanYao/Delete/5

        public ActionResult Delete(int id = 0)
        {
            canyao canyao = db.canyaos.Find(id);
            if (canyao == null)
            {
                return HttpNotFound();
            }
            return View(canyao);
        }

        //
        // POST: /CanYao/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            canyao canyao = db.canyaos.Find(id);
            db.canyaos.Remove(canyao);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}